<template>
    <view class="curve">
        <view v-if="!historylist" class="page_dcenter_null">
            <img class="page_dcenter_null_img" src="../../../static/img_null_bookbuilding.png" />
            <view>暂无记录</view>
        </view>
        <view v-else scroll-y class="pagses">
            <view class="uni-list">
                <view class="uni-list-cell">
                    <view class="uni-list-cell-db">
                        <picker @change="bindPickerChange" :value="index" :range="array">
                            <view class="uni-input">{{array[index]}}</view>
                        </picker>
                    </view>
                </view>
            </view>
            <view class="fm_top" v-if="itemsList.length>0">
                <div v-for="(item, index) in itemsList" :key="index">
                    <cu-caves :index="index" :row="item" />
                </div>
            </view>
        </view>
    </view>
</template>
<script>
import cuCaves from "./cucaves.vue";
export default {
    data() {
        return {
            historylist: null,
            itemsList: [],
            index: 1,
            array: ["今天", "最近7天", "最近30天"],
            qudata: {
                monitorTypeId: "316252407883640832",
                fromType: 7,
            },
        };
    },
    components: {
        cuCaves,
    },
    mounted() {
        var _this = this;
        _this.getList();
    },
    methods: {
        bindPickerChange(e) {
            var time = e.target.value;
            if (time == 0) {
                this.qudata.fromType = 1;
            } else if (time == 1) {
                this.qudata.fromType = 7;
            } else if (time == 2) {
                this.qudata.fromType = 30;
            }
            this.index = time;
            this.getList();
        },
        getperiod(val) {
            var a = "";
            switch (val) {
                case 0:
                    a = "早餐前";
                    break;
                case 1:
                    a = "早餐后";
                    break;
                case 2:
                    a = "午餐前";
                    break;
                case 3:
                    a = "午餐后";
                    break;
                case 4:
                    a = "晚餐前";
                    break;
                case 5:
                    a = "晚餐后";
                    break;
                case 6:
                    a = "睡前";
                    break;
                case 7:
                    a = "凌晨";
                    break;
                default:
                    a = "";
            }
            return a;
        },
        getList() {
            var _this = this;
            _this.itemsList = [];
            _this.$ajaxs
                .get("/mobile/v1/monitor/getCurveForm", _this.qudata)
                .then((res) => {
                    if (res.status == 200) {
                        _this.historylist = res.content;
                        var data = [
                            {
                                name: "餐前/睡前血糖",
                                maxValue: _this.historylist.beforeMealMaxValue,
                                minValue: _this.historylist.beforeMealMinValue,
                                hPressure:
                                    _this.historylist.beforeMealOrHighPressure,
                            },
                            {
                                name: "餐后血糖",
                                maxValue: _this.historylist.afterMealMaxValue,
                                minValue: _this.historylist.afterMealMinValue,
                                hPressure:
                                    _this.historylist.afterMealOrLowPressure,
                            },
                            {
                                name: "凌晨血糖",
                                maxValue: _this.historylist.beforeDawnMaxValue,
                                minValue: _this.historylist.beforeDawnMinValue,
                                hPressure:
                                    _this.historylist.beforeDawnOrPulseRate,
                            },
                        ];
                        _this.itemsList = data;
                    } else {
                        uni.showToast({
                            title: "请检查网络~",
                            icon: "none",
                        });
                    }
                })
                .catch((err) => reject(err));
        },
        tips() {
            uni.showModal({
                title: "温馨提示提示",
                cancelText: "关闭",
                confirmText: "我知道了",
                confirmColor: "#FA4D93",
                content:
                    "血压异常时，请关注测量前3小时的用药及生活方式记录，找到原因，以后注意。",
                success(res) {
                    if (res.confirm) {
                    } else if (res.cancel) {
                    }
                },
            });
        },
    },
};
</script>

<style scoped lang="scss">
.curve {
    height: calc(100% - 88upx);
    .page_dcenter_null {
        padding-top: 180upx;
        text-align: center;
        .page_dcenter_null_img {
            height: 180upx;
            width: 162upx;
        }
        // div {
        //     color: #999;
        //     font-size: 28upx;
        //     height: 40upx;
        //     line-height: 40upx;
        // }
    }
    .pagses {
        height: 100%;
        .uni-input {
            margin-top: 20upx;
            background: #fff;
            text-align: right;
            position: relative;
            height: 100upx;
            line-height: 100upx;
            padding-right: 40upx;
        }
        .uni-input::after {
            content: "";
            position: absolute;
            top: 46upx;
            right: 15upx;
            width: 0;
            height: 0;
            border-right: 10upx solid transparent;
            border-left: 10upx solid transparent;
            border-top: 10upx solid #333;
        }
    }
}
</style>